<template>
  <div>
    <Card class="card clear-float">
      <p class="card-title" slot="title">{{$t('user_edit')}}</p>
      <agent-form-info
        :inModal="inModal"
        :data="formData"
        :rules="rules"
        @save="save"
      ></agent-form-info>
    </Card>
  </div>
</template>

<script>
import AgentFormInfo from './components/agentEdit_form_info'
import { getOperatorInfo, updateAgent } from '@/api/data2'

export default {
  name: 'user_edit',
  components: {
    AgentFormInfo
  },
  data () {
    return {
      formData: {
        address: '',
        name: '',
        person: '',
        pictures: '',
        remark: '',
        tel1: '',
        tel2: '',
        type: ''
      },
      inModal: false,
      rules: {
        name: [{ required: true, message: this.$t('_-lv23N740OG1YfhrHybp'), trigger: 'blur' }]
      }
    }
  },
  mounted () {
    this.queryData()
  },
  methods: {
    async queryData () {
      const { code, data, desc } = await getOperatorInfo({
        id: this.$store.state.user.operatorId
      })
      if (code == 200) {
        this.formData = data
      } else {
        this.$Message.error(desc)
      }
    },
    async save (options) {
      const { code, data, desc } = await updateAgent(options)
      if (code == 200) {
        this.$Message.success(this.$t('zs9Qb3hoAGt6cd4DjeGow'))
        this.queryData()
      } else {
        this.$Message.error(desc)
      }
    }
  }
}
</script>
